package com.ruoyi.web.controller.server;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.AppUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.server.domain.dto.*;
import com.ruoyi.server.domain.vo.ServerTaskAppVO;
import com.ruoyi.server.service.IServerTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 区服任务Controller
 *
 * @author ghostmen
 * @date 2024-10-31
 */
@Validated
@RestController
@RequestMapping("/app/server/task")
@Api(value = "区服任务", tags = "首页-区服任务")
public class AppServerTaskController extends BaseController {

    @Autowired
    private IServerTaskService serverTaskService;

    /**
     * 查询区服任务列表
     */
    @GetMapping("/taskListByRegionId")
    @ApiOperation(value = "查询区服任务列表", notes = "传入serverTask")
    public TableDataInfo list(@Valid ServerTaskPageDTO pageDTO) {
        AppUser appUser = getLoginAppUser().getAppUser();
        pageDTO.setRegionId(appUser.getRegionId());
        pageDTO.setUserId(appUser.getUserId());
        startPage();
        PageInfo<ServerTaskAppVO> list = serverTaskService.taskListByRegionId(pageDTO);
        return getDataTable(list);
    }

    /**
     * 获取区服任务详细信息
     */
    @GetMapping(value = "/details/{taskId}")
    @ApiOperation(value = "获取区服任务详细信息", notes = "传入taskId")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
        return success(serverTaskService.getAppServerTaskByTaskId(taskId));
    }

}
